package com.tiancheng.trade.authserver.model.reponse;

import com.tiancheng.trade.authserver.entity.AuthOrg;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;

import java.util.List;

@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
public class UserOrgInfoResult {
    private String id;
    private String name;
    private String code;
    private String describe;
    private String parentId;
    private String[] parentIds;
    private AuthOrg.OrgType type;
    private String typeName;
    private String applicationId;
    private Integer order;
    private List<UserOrgInfoResult> subordinates;

    public UserOrgInfoResult(AuthOrg org) {
        if (org != null) {
            BeanUtils.copyProperties(org, this, "parentIds");
            if (!";".equals(org.getParentIds())) {
                this.setParentIds(org.getParentIds().split(";"));
            }
            this.setTypeName(org.getType());
        }
    }
}
